<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Wait for activity from one of the job servers</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="gearmanworker.unregisterall.html">« GearmanWorker::unregisterAll</a></li>
      <li style="float: right;"><a href="gearmanworker.work.html">GearmanWorker::work »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.gearmanworker.html">GearmanWorker</a></li>
    <li>Wait for activity from one of the job servers</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="gearmanworker.wait" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">GearmanWorker::wait</h1>
  <p class="verinfo">(PECL gearman &gt;= 0.6.0)</p><p class="refpurpose"><span class="refname">GearmanWorker::wait</span> &mdash; <span class="dc-title">Wait for activity from one of the job servers</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-gearmanworker.wait-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>GearmanWorker::wait</strong></span>(): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Causes the worker to wait for activity from one of the Gearman job servers when operating
   in non-blocking I/O mode.  On failure, issues a <strong><code>E_WARNING</code></strong> with the last Gearman error
   encountered.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-gearmanworker.wait-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-gearmanworker.wait-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-gearmanworker.wait-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4321">
    <p><strong>示例 #1 Running worker in non-blocking mode</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Starting\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">#&nbsp;Create&nbsp;our&nbsp;worker&nbsp;object<br /></span><span style="color: #0000BB">$worker</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">GearmanWorker</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">#&nbsp;Make&nbsp;the&nbsp;worker&nbsp;non-blocking<br /></span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addOptions</span><span style="color: #007700">(</span><span style="color: #0000BB">GEARMAN_WORKER_NON_BLOCKING</span><span style="color: #007700">);&nbsp;<br /><br /></span><span style="color: #FF8000">#&nbsp;Add&nbsp;the&nbsp;default&nbsp;server&nbsp;(localhost,&nbsp;port&nbsp;4730)<br /></span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">();&nbsp;<br /><br /></span><span style="color: #FF8000">#&nbsp;Add&nbsp;our&nbsp;reverse&nbsp;function<br /></span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">'reverse'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'reverse_fn'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">#&nbsp;Try&nbsp;to&nbsp;grab&nbsp;a&nbsp;job<br /></span><span style="color: #007700">while&nbsp;(@</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">work</span><span style="color: #007700">()&nbsp;||<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">returnCode</span><span style="color: #007700">()&nbsp;==&nbsp;</span><span style="color: #0000BB">GEARMAN_IO_WAIT&nbsp;</span><span style="color: #007700">||<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">returnCode</span><span style="color: #007700">()&nbsp;==&nbsp;</span><span style="color: #0000BB">GEARMAN_NO_JOBS</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">returnCode</span><span style="color: #007700">()&nbsp;==&nbsp;</span><span style="color: #0000BB">GEARMAN_SUCCESS</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;continue;<br /><br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Waiting&nbsp;for&nbsp;next&nbsp;job...\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;if&nbsp;(!@</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">wait</span><span style="color: #007700">())&nbsp;<br />&nbsp;&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">returnCode</span><span style="color: #007700">()&nbsp;==&nbsp;</span><span style="color: #0000BB">GEARMAN_NO_ACTIVE_FDS</span><span style="color: #007700">)&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#&nbsp;We&nbsp;are&nbsp;not&nbsp;connected&nbsp;to&nbsp;any&nbsp;servers,&nbsp;so&nbsp;wait&nbsp;a&nbsp;bit&nbsp;before&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;trying&nbsp;to&nbsp;reconnect.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">5</span><span style="color: #007700">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;<br />&nbsp;&nbsp;}&nbsp;<br />}&nbsp;<br /><br />echo&nbsp;</span><span style="color: #DD0000">"Worker&nbsp;Error:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />function&nbsp;</span><span style="color: #0000BB">reverse_fn</span><span style="color: #007700">(</span><span style="color: #0000BB">$job</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">strrev</span><span style="color: #007700">(</span><span style="color: #0000BB">$job</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">workload</span><span style="color: #007700">());<br />}<br /><br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-gearmanworker.wait-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="gearmanworker.work.html" class="methodname" rel="rdfs-seeAlso">GearmanWorker::work()</a> - Wait for and perform jobs</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>